//使用shm  读取数据

#include "comm.hpp"

const int flags = IPC_CREAT;

int main()
{
    //用相同的key去找到shm
    //然后attach
    key_t key = GetKey();
    int shmid = shmget(key, SHM_SIZE, flags);
    if (shmid < 0)
    {
        cerr << "cli shmge err" << endl;
    }
    char *str = (char *)shmat(shmid, nullptr, 0);
    if (*((int *)str) == -1)
    {
        cerr << "shat err" << endl;
    }
    cout << "cli shmat success" << endl;
    //使用数据
    int cnt=5;
    while(cnt--)
    {
        sleep(1);
        printf("cli:%s \n",str);
    }
    cout<<"cli 使用数完毕";
    sleep(1);
    shmdt(str);
    cout<<"cli shdt success"<<endl;
    return 0;
}